/*
 * @Descripttion: 患者登录
 * @version: 1.0
 * @Author: 自由如风
 * @Date: 2021-05-02 10:24:37
 * @LastEditors: 自由如风
 * @LastEditTime: 2021-05-04 12:35:34
 */
const DB = require("../../lib/DB")
const { Success } = require("../../lib/Response")

module.exports = async function (ctx, next) {
    const { number, pwd } = ctx.request.body
    try {
        const patient = await DB.models.patient.findOne({ where: { number, pwd } })
        // 设置 session
        ctx.session.patient = patient.toJSON();
        ctx.body = new Success(patient.toJSON());
        await next();
    } catch (e) {
        console.error(e)
        throw new Error("账号或密码错误！")
    }
}
